package com.cloudcentral.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cloudcentral.entity.User;

/**
 * <p>
 * 系统用户表 Mapper 接口
 * </p>
 *
 * @author Administrator
 * @since 2023-10-27
 */
public interface UserBaseMapper extends BaseMapper<User> {
  default User selectByPhone(String phone) {
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("phone", phone);
    return selectOne(queryWrapper);
  }

  default User selectByUsername(String username) {
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("username", username);
    return selectOne(queryWrapper);
  }

  default User selectUser(String name) {
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("username", name).or().eq("phone", name);
    return selectOne(queryWrapper);
  }
}
